﻿using System;
class FillingMatrix
{
    static void Main()
    {
        int matrixSize;
        int number = 0;
        Console.Write("please enter size of matrix: ");
        while (true)
        {
            try
            {
                matrixSize = int.Parse(Console.ReadLine());
                break;
            }
            catch (Exception)
            {
                Console.Write("Please re-enter size:");
            }
        }
        int[,] theArray;
        theArray = new int[matrixSize, matrixSize];
        //   a) **************************************************************
        for (int i = 0; i < matrixSize; i++)
        {
            for (int j = 0; j < matrixSize; j++)
            {
                number++;
                theArray[i, j] = number;
            }
        }
        Console.WriteLine("a)");
        for (int i = 0; i < matrixSize; i++)
        {
            for (int j = 0; j < matrixSize; j++)
            {
                if (j == (matrixSize - 1))
                {
                    Console.WriteLine("{0,-2} ", theArray[j, i]);
                }
                else
                {
                    Console.Write("{0,-2} ", theArray[j, i]);
                }
            }
        }
        Console.WriteLine();
        //   b) **************************************************************
        number = 0;
        for (int i = 0; i < matrixSize; i++)
        {
            if (i % 2 == 1)
            {
                for (int j = matrixSize - 1; j >= 0; j--)
                {
                    number++;
                    theArray[i, j] = number;
                }
            }
            else
            {
                for (int j = 0; j < matrixSize; j++)
                {
                    number++;
                    theArray[i, j] = number;
                }
            }
        }
        Console.WriteLine("b)");
        for (int i = 0; i < matrixSize; i++)
        {
            for (int j = 0; j < matrixSize; j++)
            {
                if (j == (matrixSize - 1))
                {
                    Console.WriteLine("{0,-2} ", theArray[j, i]);
                }
                else
                {
                    Console.Write("{0,-2} ", theArray[j, i]);
                }
            }
        }
        //   c) **************************************************************
        //number = 0;

        //for (int i = 0; i < matrixSize; i++)
        //{
        //    for (int j = matrixSize - 1; j >= matrixSize - i - 1 - j; j--)
        //    {
        //        number++;
        //        theArray[i, j] = number;
                
        //    }

        //}
        //Console.WriteLine("c)");
        //for (int i = 0; i < matrixSize; i++)
        //{
        //    for (int j = 0; j < matrixSize; j++)
        //    {
        //        if (j == (matrixSize - 1))
        //        {
        //            Console.WriteLine("{0,-2} ", theArray[j, i]);
        //        }
        //        else
        //        {
        //            Console.Write("{0,-2} ", theArray[j, i]);
        //        }
        //    }
        //}
        Console.ReadLine();
    }
}

